<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
    <script src="./layui/layui.js"></script>
    <script src="./js/jquery-3.5.1.js"></script>
</head>
<body >
<div class="layui-row layui-col-space5">
    <div class="layui-col-md5">
        <div class="layui-row grid-demo" style="padding: 10px 10px">
            <div class="layui-col-md3">
                <h1>公告发布</h1>
                <hr class="layui-bg-gray">
            </div>
            <div class="layui-col-md9">
            </div>
            <div class="layui-col-md12" style="padding-top: 20px">
                <form class="layui-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input" id="title">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">公告内容</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容" class="layui-textarea" name="content" id="content"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="*">发布</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form','layer'], function(){
        var form = layui.form;
        let layer = layui.layer;
        form.on('submit(*)', function(data){
            if (data.field.title===""||data.field.content===""){
                    layer.msg("内容填写不完整")
            }else {
                let s = JSON.stringify(data.field);
                layer.open({
                    title: '公告发布',
                    content: '是否发布公告'
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        //按钮【按钮一】的回调
                        $.post("/insertNotice",{"form":s},function (data) {
                            if (data.code===200){
                                window.location.href = "noticerelease.html"
                            }else {
                                layer.msg(data.msg)
                                return false;
                            }
                        },"json")
                    }
                    ,btn2: function(index, layero){
                        //按钮【按钮二】的回调

                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                    ,cancel: function(){
                        //右上角关闭回调

                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
            }
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //各种基于事件的操作，下面会有进一步介绍
    });
</script>
</body>
</html>